package org.zju.demo;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.HttpClientBuilder;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;

/**
 * Created by ZJDX on 2015/9/16.
 */
public class testImage {
    private static String BASE_URL = "http://10.214.143.25:8080";

    private static void frame(String uri) {
        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpGet get = new HttpGet(uri);
        try{
            HttpResponse response = httpClient.execute(get);
            System.out.println("response code " + response.getStatusLine().getStatusCode());
            if (response.getStatusLine().getStatusCode() == 200) {
                File storeFile = new File("E:\\" + System.currentTimeMillis() + ".png");
                FileOutputStream outputStream = new FileOutputStream(storeFile);
                InputStream inputStream = response.getEntity().getContent();
                byte[] bytes = new byte[1024];
                int count = 0;
                while ((count = inputStream.read(bytes)) != -1) {
                    outputStream.write(bytes, 0, count);
                }
                inputStream.close();
                outputStream.close();
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
    }



    public static void main(String[] args) {
        frame("http://localhost:8080/static/images/ProductImage/1442151569435.png");
    }
}
